<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品变价导出</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script src="${Plugins}/jquery/jquery-1.4.4.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/utils.js" type="text/javascript"></script>
<style type="text/css">
#searchbar{
	margin-bottom: 10px;
}
.navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
.l-button-search{
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
</style>
</head>
<body style="padding:6px; overflow:hidden;">
<div id="">
	<div class="navbar"><span>您当前的位置：商品管理 &gt;商品变价导出列表 </span></div>
	<br/>
	<form action="#"  name="queryForm" id="queryForm" method="POST">
		供应商编号：<input type="text" id="supplierNo" name="supplierNo" size="18" maxLength="40" value="${changePrice.supplierNo }">&nbsp;&nbsp;&nbsp;&nbsp;
		供应商名称：<input type="text" id="supplierName" name="supplierName" size="18" maxLength="40" value="${changePrice.supplierName }">&nbsp;&nbsp;&nbsp;&nbsp;
		促销变价时段：<input id="validTimeStart" type="text" name="validTimeStart" readonly="readonly" value="${changePrice.validTimeStart }" class="Wdate" value="" size="21"
    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,maxDate:'#F{$dp.$D(\'validTimeEnd\')||\'2020-10-01\'}'})" >~
    	<input id="validTimeEnd" type="text" name="validTimeEnd" readonly="readonly" value="${changePrice.validTimeEnd }" class="Wdate" value="" size="21"
    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,minDate:'#F{$dp.$D(\'validTimeStart\')||\'2013-01-01\'}'})" ><br><br>
		<table cellpadding="0" cellspacing="0">
		<tr>
	       <td align="right" class="l-table-edit-td s-lab">品牌：<input type="text" id="brandName" name="brandName" size="18" maxLength="40" value="${changePrice.brandName }">&nbsp;&nbsp;&nbsp;&nbsp;</td>
	       <td align="right" class="l-table-edit-td s-lab">分类：</td>
	       <td align="left" class="l-table-edit-td s-lab">
	       	<div id="catDiv"></div>
	       </td>
	       <td align="left"><input  type="submit" value="查询" class="l-button-search"  >&nbsp;&nbsp;&nbsp;&nbsp;<input  type="button" id="resetButton" value="重置" class="l-button-search" ></td>
	   	</tr>
		</table>
	</form>
	<br/>
</div>
<div id="maingrid6" style="margin:0; padding:0"></div>
  <div style="display:none;">
  <!-- g data total ttt -->
</div>
<script type="text/javascript">
	var basePath="${BasePath}";
    var grid = null;
    var poListExportData = null;
    var search = "${changePrice.search }";
    var catNo = "${changePrice.catNo }";
    $(function () {
    	$('#resetButton').click(function() {
        	$('#supplierNo').val('');
        	$('#supplierName').val('');
        	$('#brandName').val('');
        	$('#validTimeStart').val('');
        	$('#validTimeEnd').val('');
        	$("select[name=catNo]").eq(0).nextAll().remove();
        	$("select").find("option[value='0']").attr("selected","true");  
        });
   		//初始加载分类
       	parentCat("0");
   		//if (search == 'true') {
   			var catNos = catNo.split(',');
   			if (catNos[0] != '0') {
   				for (var i=0; i<catNos.length; i=i+2) {
   					sonCat(catNos[i],catNos[i+2]);
   				}
   			}
   		//}
   		
        grid = $("#maingrid6").ligerGrid({
            columns: [
            { display: '货品条码', name: 'prodBarCode'},
            { display: '货品编码', name: 'prodNo' },
            { display: '商品分类', name: 'catName'},
            { display: '商品品牌', name: 'brandName' },
            { display: '商品名称', name: 'commoName' },
            { display: '商品规格', name: 'specName' },            
            { display: '正常含税成本', name: 'originalCost' },
            { display: '正常未税成本', name: 'unOriginalCost' },
            { display: '正常含税零售', name: 'originalRetailCost' },
            { display: '正常未税零售', name: 'unOriginalRetailCost' },
            { display: '正常毛利率(%)', name: 'originalRate' },
            { display: '促销含税成本', name: 'promotionsCost' },
            { display: '促销未税成本', name: 'unPromotionsCost' },
            { display: '促销含税零售', name: 'promotionsRetailCost' },
            { display: '促销未税零售', name: 'unPromotionsRetailCost' },
            { display: '促销毛利率(%)', name: 'promotionsRate' },
            { display: '税率(%)', name: 'prodRate' },
            { display: '库存数量', name: 'prodInventory' },
            { display: '促销变价开始时间', name: 'validTimeStart'  },
            { display: '促销变价结束时间', name: 'validTimeEnd' },
            { display: '供应商编号', name: 'supplierNo' },
            { display: '供应商名称', name: 'supplierName' }
            ], 
            pageSize:30,
            width: '100%',
            height: '100%',
            columnWidth: '10%',
            dataType: 'server', 
            dataAction: 'server',
            pagesizeParmName: 'pageSize',
            parms: [
					{name: "supplierNo", value:$('#supplierNo').val()},
					{name: "supplierName", value:$('#supplierName').val()},
					{name: "validTimeStart", value:$("#validTimeStart").val()},
					{name: "validTimeEnd", value:$("#validTimeEnd").val()},
					{name: "brandName", value:$("#brandName").val()},
					{name: "catNo", value:'${changePrice.catNo }'}
                    ],
            url: "list_prod_change_price.do",
            toolbar: {items: [
              	{text: '导出EXCEL', click: doExportExcel, icon: "print"}
            ]}
        });
    });
    
	function doExportExcel() {
		var supplierNo = encodeURI(encodeURI($('#supplierNo').val()));
		var supplierName = encodeURI(encodeURI($('#supplierName').val()));
		var validTimeStart = $('#validTimeStart').val();
		var validTimeEnd = $('#validTimeEnd').val();
		var brandName = encodeURI(encodeURI($('#brandName').val()));
		var catNos = $("select[name=catNo]").serializeArray();
		var catNo = '';
		for (var i=0; i<catNos.length; i++) {
			catNo += catNos[i].value + ',';
		}
		catNo = catNo.substr(0, catNo.length-1);
		catNo = encodeURI(encodeURI(catNo));
		if(supplierNo==""&&supplierName==""&&validTimeStart==""&&validTimeEnd==""&&brandName==""&&catNo==0){
			$.ligerDialog.warn("选先输入查询条件再导出数据!");
			return;
		}
		var params = '?catNo=' + catNo + '&supplierNo=' + supplierNo + '&supplierName=' + supplierName + '&validTimeStart=' 
				+ validTimeStart + '&validTimeEnd=' + validTimeEnd + '&brandName=' + brandName;
		window.location.href = 'doExportExcel.do' + params;
	}
	//获取所有父类
	function parentCat(catPno) {
		var param = new Array();
		var initCatPno = catPno;
		if(catPno!='0'){
			param = {"catNo":catPno};
		}else{
			param = {"catPno":"0"};
		};
		
		var isBreak = true;
		var selected = catNo.split(',')[0];
			$.post(basePath + '/product/cat/getAjaxNextCommodityCat.do', param,
			function(data) {
				if (data != "") {
					var obj = eval('(' + data + ')');
					catPno = obj[0].catPno;
						var t = "<select name='catNo' onchange='getProCat(this);'>";
						if(catPno == '0'){
							t+="<option value='0'>顶级分类</option>";
						}else{
							t+="<option value=''>请选择</option>";
						}
						
						for ( var i = 0; i < obj.length; i++) {
							if (selected == obj[i].catNo) {
								t+="<option pno='"+obj[i].catPno+"' value='"+obj[i].catNo+","+obj[i].catName+"' selected='selected'>"+obj[i].catName+"</option>";
							} else {
								t+="<option pno='"+obj[i].catPno+"' value='"+obj[i].catNo+","+obj[i].catName+"'>"+obj[i].catName+"</option>";
							};
						}
						t+="</select>";
						$("#catDiv").prepend(t);
						param = {"catNo" : catPno};
						if(catPno == '0') isBreak =  false;
				}
				});
	};

	//获取分类
	function getProCat(o){
		$("select[name=catNo]").eq($(o).index()).nextAll().remove();
		
		if(o.value == "" || o.value == null){
			$("#catNo").val($("select[name=catNo]").eq($(o).index()-1).val());
		}else{
			$("#catNo").val(o.value);
		}
		
		if(o.value == "0") return false;
		sonCat(o.value);
	}

	//获取下一级所属子类  val:分类编码
	function sonCat(val){
		if(val == "" || val == null) return false;
		val = val.split(',')[0];
		$.post(
				basePath + '/product/cat/getAjaxNextCommodityCat.do', 
				{"catPno" : val}, 
				function(data) {
					if(data != ""){
						var obj=eval('(' + data + ')');
						var t = "<select name='catNo' onchange='getProCat(this);'>";
						t += "<option value=''>请选择</option>";
						for(var i in obj){
							t +="<option pno='"+obj[i].catPno+"' value='"+obj[i].catNo+","+obj[i].catName+"'>"+obj[i].catName+"</option>";
						};
						t += "<select>";
						$("#catDiv").append(t);
					};
				}
		);
	}
	
	//获取下一级所属子类  val:分类编码
	function sonCat(val, child){
		if(val == "" || val == null) return false;
		val = val.split(',')[0];
		$.post(
				basePath + '/product/cat/getAjaxNextCommodityCat.do', 
				{"catPno" : val}, 
				function(data) {
					if(data != ""){
						var obj=eval('(' + data + ')');
						var t = "<select name='catNo' onchange='getProCat(this);'>";
						t += "<option value=''>请选择</option>";
						for(var i in obj){
							if (child == obj[i].catNo) {
								t +="<option pno='"+obj[i].catPno+"' value='"+obj[i].catNo+","+obj[i].catName+"' selected='selected'>"+obj[i].catName+"</option>"; 
							} else {
								t +="<option pno='"+obj[i].catPno+"' value='"+obj[i].catNo+","+obj[i].catName+"'>"+obj[i].catName+"</option>";
							}
						};
						t += "<select>";
						$("#catDiv").append(t);
					};
				}
		);
	}
</script>
</body>
</html>